package chapter4.parallel;

import com.rabbitmq.client.*;
import util.Conn;

import java.io.IOException;

/**
 * Created by uu on 2017/6/19.
 */
public class points_consumer {
    private static boolean autoAck = true; // 是否默认Ack
    public static void main(String[] args) throws Exception{
        Connection conn = new Conn().getConnection();
        final Channel channel= conn.createChannel();
        channel.exchangeDeclare("upload-pictures","fanout",true);
        channel.queueDeclare("add-points",true,false,false,null);
        channel.queueBind("add-points","upload-pictures","");
        System.out.println("start consume!");
            channel.basicConsume("add-points", autoAck, "consumer_tag",
                    new DefaultConsumer(channel) {
                        @Override
                        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                            String routingKey = envelope.getRoutingKey();
                            String contentType = properties.getContentType();
                            long deliveryTag = envelope.getDeliveryTag();
                            // (process the message components here ...)
                            System.out.println(contentType);
                            System.out.println(new String(body, "UTF-8"));
                            channel.basicAck(deliveryTag, false);
                        }
                    });
            channel.close();
            conn.close();
    }
}
